package br.uefs.cedoc.controle.serie;

import br.uefs.cedoc.controle.*;
import javax.servlet.http.HttpServletRequest;
import br.uefs.cedoc.db.*;
import br.uefs.cedoc.db.serie.DBSerie;
import br.uefs.cedoc.entidades.*;
import java.sql.SQLException;

public class DeleteSerieCommand implements Command {

    private String next;

    public DeleteSerieCommand(String next) {
        this.next = next;
    }

    public String execute(HttpServletRequest req)
            throws CommandException {
        try {
            if (CommandToken.isValid(req)) {
                DBSerie dbserie = new DBSerie();
                SerieBean serie = new SerieBean();
                int id = Integer.parseInt(req.getParameter("id"));
                dbserie.removerSerie(id);
                req.setAttribute("status.msg", "Se&ccedil;&atilde;o deletada!");
            } else {
                req.setAttribute("status.msg", "Nao foi possivel deletar!");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        } 
        return next;

    }
}
